package cn.iocoder.yudao.module.book.controller.app;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.book.controller.app.vo.*;
import cn.iocoder.yudao.module.book.service.app.BookClassManagementService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;

@RestController
@RequestMapping("/bookClassManagement")
@Validated
public class AppBookClassManagementController {

    @Resource
    private BookClassManagementService bookClassManagementService;

    @PostMapping("/createBookClassManagement")
    @Operation(summary = "创建班级")
    public CommonResult<Long> createBookClassManagement(@Validated @RequestBody BookClassManagementReqVO bookClassManagementReqVO) {
        return CommonResult.success(bookClassManagementService.createBookClassManagement(bookClassManagementReqVO));
    }

    @PostMapping("/JoinBookClassManagement")
    @Operation(summary = "加入班级")
    public CommonResult<Long> JoinBookClassManagement(@Validated @RequestBody BookClassManagementMemberReqVO bookClassManagementMemberReqVO) {
        return CommonResult.success(bookClassManagementService.JoinBookClassManagement(bookClassManagementMemberReqVO));
    }

    @GetMapping("/getBookClassManagementById")
    @Operation(summary = "获取班级信息")
    public CommonResult<BookClassManagementRespVO> getBookClassManagementById(@PathParam("id") String id) {
        return CommonResult.success(bookClassManagementService.getBookClassManagementById(id));
    }

    @GetMapping("/getBookClassManagementList")
    @Operation(summary = "获取班级列表")
    public CommonResult<List<BookClassManagementRespVO>> getBookClassManagementList() {
        return CommonResult.success(bookClassManagementService.getClassManagementList());
    }

    @PutMapping("/updateBookClassManagement")
    @Operation(summary = "更新班级信息")
    public CommonResult<Boolean> updateBookClassManagement(@Validated @RequestBody BookClassManagementReqVO bookClassManagementReqVO) {
        bookClassManagementService.updateBookClassManagement(bookClassManagementReqVO);
        return CommonResult.success(true);
    }

    @GetMapping("/getBookClassManagementBookSchoolAssignmentList/{id}")
    @Operation(summary = "根据作业ID获取作业详情")
    public CommonResult<BookSchoolAssignmentSaveRespVO> getBookClassManagementBookSchoolAssignmentList(@PathVariable Long id) {
        BookSchoolAssignmentSaveRespVO bookSchoolAssignmentSaveRespVO = bookClassManagementService.getBookClassManagementBookSchoolAssignmentList(id);
        return CommonResult.success(bookSchoolAssignmentSaveRespVO);
    }

    @PostMapping("/submitJob")
    @Operation(summary = "提交作业")
    public CommonResult<Long> submitJob(@Validated @RequestBody BookClassAndSchoolSaveReqVO bookClassAndSchoolSaveReqVO) {
        Long jobId = bookClassManagementService.submitJob(bookClassAndSchoolSaveReqVO);
        return CommonResult.success(jobId);
    }

    @GetMapping("/deleteClass/{id}")
    @Operation(summary = "删除班级")
    public CommonResult<Boolean> deleteClass(@PathVariable String id) {
        return CommonResult.success(bookClassManagementService.deleteClass(id));
    }

    @GetMapping("/updateClassName")
    @Operation(summary = "更新班级信息")
    public CommonResult<Boolean> updateClassName(@PathParam("id") String id, @PathParam("className") String className) {
        return CommonResult.success(bookClassManagementService.updateClassName(id, className));
    }

    @GetMapping("/getClassMembers")
    @Operation(summary = "获取班级成员")
    public CommonResult<List<ClassMembersRespVO>> getClassMembers(@PathParam("classId") String classId) {
        return CommonResult.success(bookClassManagementService.getClassMembers(classId));
    }

    @GetMapping("/deleteMemberById")
    @Operation(summary = "删除班级成员")
    public CommonResult<Boolean> deleteMemberById(@PathParam("id") String id){
        return CommonResult.success(bookClassManagementService.deleteMemberById(id));
    }
}